import Atcore from '../atcore/Atcore.js';
import Hex from '../atcore/hex.js';
import test from './test.js';

test( "ATCORE");

var boundUpdate;

test( function init(){

    var core = Atcore.ATmega328P();
    // Hex.parse( blinkWithoutDelay, core.flash );
    Hex.parse( pulseIn, core.flash );

    core.exec( 1 / 1000 );

    if( typeof window !== "undefined" ){
        boundUpdate = update.bind( null, core );
        boundUpdate();
    }

    if( core.error ) throw core.error;

    this.assert
        ( !core.error )
    
} );

function update( core ){
    requestAnimationFrame( boundUpdate )
    core.update();
}

const pulseIn = `
:100000000C9462000C948A000C948A000C948A0070
:100010000C948A000C948A000C948A000C948A0038
:100020000C948A000C948A000C948A000C948A0028
:100030000C948A000C948A000C948A000C948A0018
:100040000C944A020C948A000C9418020C94F2014D
:100050000C948A000C948A000C948A000C948A00F8
:100060000C948A000C948A000000000024002700F1
:100070002A000000000023002600290000000000E4
:10008000250028002B0004040404040404040202D4
:100090000202020203030303030301020408102007
:1000A0004080010204081020010204081020000012
:1000B0000008000201000003040700000000000027
:1000C0000000490411241FBECFEFD8E0DEBFCDBF32
:1000D00011E0A0E0B1E0ECEAFBE002C005900D9277
:1000E000A032B107D9F721E0A0E2B1E001C01D9232
:1000F000AC3CB207E1F710E0C2E6D0E004C02197C3
:10010000FE010E94C905C136D107C9F70E94D90274
:100110000C94D4050C940000E7EBF0E02491E3EAA2
:10012000F0E09491EFE8F0E0E491EE2309F43BC0B5
:10013000222339F1233091F038F42130A9F0223014
:1001400001F524B52F7D12C0273091F02830A1F0A1
:100150002430B9F4209180002F7D03C020918000CD
:100160002F77209380000DC024B52F7724BD09C0C0
:100170002091B0002F7703C02091B0002F7D2093F5
:10018000B000F0E0EE0FFF1FE458FF4FA591B491CF
:100190002FB7F894EC91811103C090959E2301C074
:1001A0009E2B9C932FBF0895CF92DF92EF92FF92E8
:1001B0000F931F93CF93DF936C017A018B01C0E003
:1001C000D0E0CE15DF0589F0D8016D918D01D60103
:1001D000ED91FC910190F081E02DC6010995892BEC
:1001E00011F47E0102C02196ECCFC701DF91CF91BF
:1001F0001F910F91FF90EF90DF90CF900895089599
:1002000080E090E00895FC01538D448D252F30E06F
:10021000842F90E0821B930B541710F0CF96089513
:1002200001970895FC01918D828D981761F0828D60
:10023000DF01A80FB11D5D968C91928D9F5F9F731A
:10024000928F90E008958FEF9FEF0895FC01918DBC
:10025000828D981731F0828DE80FF11D858D90E029
:1002600008958FEF9FEF0895FC01918D228D892FC6
:1002700090E0805C9F4F821B91098F7399270895AE
:100280008FE291E00E94340121E0892B09F420E003
:10029000822F0895FC01848DDF01A80FB11DA35AA0
:1002A000BF4F2C91848D90E001968F739927848F96
:1002B000A689B7892C93A089B1898C9180648C938D
:1002C000938D848D981306C00288F389E02D808178
:1002D0008F7D80830895EF92FF920F931F93CF93AA
:1002E000DF93EC0181E0888F9B8D8C8D981305C086
:1002F000E889F989808185FD24C0F62E0B8D10E0F8
:100300000F5F1F4F0F731127E02E8C8DE8120CC06A
:100310000FB607FCFACFE889F989808185FFF5CF10
:10032000CE010E944A01F1CF8B8DFE01E80FF11D35
:10033000E35AFF4FF0820B8FEA89FB89808180624C
:1003400007C0EE89FF896083E889F989808180642C
:10035000808381E090E0DF91CF911F910F91FF901A
:10036000EF900895CF93DF93EC01888D8823C9F037
:10037000EA89FB89808185FD05C0A889B9898C91AE
:1003800086FD0FC00FB607FCF5CF808185FFF2CF49
:10039000A889B9898C9185FFEDCFCE010E944A01D1
:1003A000E7CFDF91CF91089580E090E0892B29F08D
:1003B0000E94400181110C9400000895009769F09B
:1003C000FC0101900020E9F73197AF01481B590B60
:1003D000BC018FE291E00C94D40080E090E008959D
:1003E0000E94CF051F920F920FB60F9211242F93E8
:1003F0003F934F935F936F937F938F939F93AF93AD
:10040000BF93EF93FF938FE291E00E944A01FF9127
:10041000EF91BF91AF919F918F917F916F915F917C
:100420004F913F912F910F900FBE0F901F901895F5
:100430001F920F920FB60F9211242F938F939F93B9
:10044000EF93FF93E0913F01F09140018081E091B3
:100450004501F091460182FD12C0908180914801D2
:100460008F5F8F7320914901821751F0E09148010D
:10047000F0E0E15DFE4F958F8093480101C08081DF
:10048000FF91EF919F918F912F910F900FBE0F9041
:100490001F9018951F920F920FB60F9211242F9351
:1004A0003F938F939F93AF93BF938091250190913A
:1004B0002601A0912701B09128013091240123E069
:1004C000230F2D3720F40196A11DB11D05C026E88C
:1004D000230F0296A11DB11D2093240180932501B5
:1004E00090932601A0932701B093280180912001C9
:1004F00090912101A0912201B09123010196A11DAB
:10050000B11D8093200190932101A0932201B0930B
:100510002301BF91AF919F918F913F912F910F90A8
:100520000FBE0F901F901895CF92DF92EF92FF921F
:100530000F931F93E82FF92F05C0015011092109CE
:10054000310961F1908196239417B9F305C00150E8
:1005500011092109310911F1908196239413F7CFE4
:10056000C12CD12CE12CF12C0AC08FEFC81AD80A6B
:10057000E80AF80A0C151D052E053F0579F0808163
:100580008623841791F36C2D7D2D8E2D9F2D1F9129
:100590000F91FF90EF90DF90CF90089560E070E0B2
:1005A00080E090E01F910F91FF90EF90DF90CF904F
:1005B0000895CF93DF93CDB7DEB7A1970FB6F89428
:1005C000DEBF0FBECDBF789484B5826084BD84B594
:1005D000816084BD85B5826085BD85B5816085BD3E
:1005E00080916E00816080936E00109281008091F6
:1005F000810082608093810080918100816080937E
:100600008100809180008160809380008091B100A2
:1006100084608093B1008091B00081608093B000CD
:1006200080917A00846080937A0080917A00826061
:1006300080937A0080917A00816080937A00809123
:100640007A00806880937A001092C100E3EAF0E0BB
:100650002491EFE8F0E08491882399F090E0880FEE
:10066000991FFC01E859FF4FA591B491FC01E45892
:10067000FF4F859194918FB7F894EC91E22BEC9316
:100680008FBFE4EAF0E02491E0E9F0E08491882370
:10069000C9F090E0880F991FFC01E859FF4F459180
:1006A0005491FC01E458FF4FA591B4919FB7F89481
:1006B000FA0180812095822380838C91E22FE823A8
:1006C000EC939FBFE0913F01F091400182E0808375
:1006D000E0913B01F0913C011082E0913D01F091ED
:1006E0003E018FEC808310924701E0914301F0912D
:1006F000440186E08083E0914101F09142018081D4
:1007000080618083E0914101F091420180818860A5
:100710008083E0914101F091420180818068808373
:10072000E0914101F091420180818F7D808393E0CF
:10073000E92EF12C23E2C22ED12C34EA232E30E014
:10074000332E4AE0442E512C612C712C80E00E9403
:100750008C00C7010197F1F781E00E948C00C6016F
:100760000197F1F780E00E948C00F1016491E0E9CB
:10077000F0E08491E82FF0E0EE0FFF1FEE58FF4FFE
:100780008591949100E412E42FE030E0462F0E941E
:100790009402611571058105910549F0DC01CB01D9
:1007A0000196A11DB11DBC01CD019F7003C060E089
:1007B00070E0CB0160932B0170932C0180932D018D
:1007C00090932E010E94AE0426E933E44BE05DE3F2
:1007D0000E94120520E030E040E05FE30E94120535
:1007E0000E94760470932A016093290182E191E0CE
:1007F0000E94DE012091290130912A014901330F25
:10080000AA08BB08B7FE26C0E0912F01F091300185
:100810000190F081E02D6DE28FE291E009952227B1
:100820003327A901281939094A095B0919A28E0140
:100830000F5D1F4FCA01B901A30192010E94A705D4
:10084000605DF80162938F01211531054105510565
:1008500089F715C0A501940119A28E010F5D1F4FE4
:10086000CA01B901A30192010E94A705605DF801C8
:1008700062938F01211531054105510589F7C801A2
:100880000E94DE018DE191E00E94DE010E94D40110
:100890005DCFEFE2F1E01382128288EE93E0A0E0F8
:1008A000B0E084839583A683B78384E091E091834D
:1008B000808385EC90E09587848784EC90E097872F
:1008C000868780EC90E0918B808B81EC90E0938B1D
:1008D000828B82EC90E0958B848B86EC90E0978BFA
:1008E000868B118E128E138E148E08950E947D04B5
:1008F0006894B1110C940C0508950E94F10488F0DD
:100900009F5798F0B92F9927B751B0F0E1F0660FD3
:10091000771F881F991F1AF0BA95C9F714C0B13014
:1009200091F00E940B05B1E008950C940B05672F20
:10093000782F8827B85F39F0B93FCCF38695779543
:100940006795B395D9F73EF490958095709561952C
:100950007F4F8F4F9F4F0895E89409C097FB3EF457
:1009600090958095709561957F4F8F4F9F4F9923FC
:10097000A9F0F92F96E9BB279395F695879577957A
:100980006795B795F111F8CFFAF4BB0F11F460FF3A
:100990001BC06F5F7F4F8F4F9F4F16C0882311F092
:1009A00096E911C0772321F09EE8872F762F05C0A6
:1009B000662371F096E8862F70E060E02AF09A9541
:1009C000660F771F881FDAF7880F9695879597F936
:1009D000089557FD9058440F551F59F05F3F71F02F
:1009E0004795880F97FB991F61F09F3F79F0879596
:1009F0000895121613061406551FF2CF4695F1DF1F
:100A000008C0161617061806991FF1CF86957105AE
:100A1000610508940895E894BB2766277727CB01E2
:100A200097F908950E9425050C9496050E94880563
:100A300038F00E948F0520F0952311F00C947F056B
:100A40000C94850511240C940C050E94E90470F3A4
:100A5000959FC1F3950F50E0551F629FF001729F63
:100A6000BB27F00DB11D639FAA27F00DB11DAA1F72
:100A7000649F6627B00DA11D661F829F2227B00DBF
:100A8000A11D621F739FB00DA11D621F839FA00D4A
:100A9000611D221F749F3327A00D611D231F849F9A
:100AA000600D211D822F762F6A2F11249F575040F1
:100AB0009AF0F1F088234AF0EE0FFF1FBB1F661F6C
:100AC000771F881F91505040A9F79E3F510580F035
:100AD0000C947F050C940C055F3FE4F3983ED4F32F
:100AE000869577956795B795F795E7959F5FC1F7D9
:100AF000FE2B880F911D9695879597F9089597F984
:100B00009F6780E870E060E008959FEF80EC0895B3
:100B100000240A94161617061806090608950024DC
:100B20000A9412161306140605060895092E039456
:100B3000000C11F4882352F0BB0F40F4BF2B11F4CA
:100B400060FF04C06F5F7F4F8F4F9F4F0895A1E2FA
:100B50001A2EAA1BBB1BFD010DC0AA1FBB1FEE1F37
:100B6000FF1FA217B307E407F50720F0A21BB30B82
:100B7000E40BF50B661F771F881F991F1A9469F7FE
:100B800060957095809590959B01AC01BD01CF015A
:100B90000895EE0FFF1F0590F491E02D099481E078
:0C0BA00090E0F8940C94D405F894FFCF7A
:100BAC00000000006B01D4000301B20134011201FA
:100BBC00260144697374616E63653A20000D0A0066
:00000001FF
`;

const blinkWithoutDelay = `
:100000000C945C000C946E000C946E000C946E00CA
:100010000C946E000C946E000C946E000C946E00A8
:100020000C946E000C946E000C946E000C946E0098
:100030000C946E000C946E000C946E000C946E0088
:100040000C9470000C946E000C946E000C946E0076
:100050000C946E000C946E000C946E000C946E0068
:100060000C946E000C946E00000000002400270029
:100070002A0000000000250028002B0004040404CE
:100080000404040402020202020203030303030342
:10009000010204081020408001020408102001021F
:1000A00004081020000000080002010000030407FB
:1000B000000000000000000011241FBECFEFD8E0B8
:1000C000DEBFCDBF21E0A0E0B1E001C01D92AF30A6
:1000D000B207E1F70E94BA000C94AD010C94000045
:1000E0001F920F920FB60F9211242F933F938F936D
:1000F0009F93AF93BF938091050190910601A091CA
:100100000701B09108013091040123E0230F2D373E
:1001100020F40196A11DB11D05C026E8230F02960B
:10012000A11DB11D20930401809305019093060148
:10013000A0930701B0930801809100019091010103
:10014000A0910201B09103010196A11DB11D809300
:10015000000190930101A0930201B0930301BF91AC
:10016000AF919F918F913F912F910F900FBE0F9064
:100170001F901895789484B5826084BD84B58160A1
:1001800084BD85B5826085BD85B5816085BD809162
:100190006E00816080936E001092810080918100DA
:1001A00082608093810080918100816080938100D2
:1001B000809180008160809380008091B100846094
:1001C0008093B1008091B00081608093B0008091F5
:1001D0007A00846080937A0080917A0082608093B4
:1001E0007A0080917A00816080937A0080917A0011
:1001F000806880937A001092C100CDE9D0E0FE01C2
:10020000249109E810E0F8018491882399F090E0A6
:10021000880F991FFC01E859FF4FA591B4918E58A2
:100220009F4FFC01459154918FB7F8949C91292BD5
:100230002C938FBF91EBE92E90E0F92E20E0C22E97
:1002400020E0D22EAA24A394B12C2FB7F894809149
:10025000050190910601A0910701B09108012FBFFF
:1002600040910B0150910C0160910D0170910E01B4
:100270003C014D01641A750A860A970A28EE621637
:1002800023E072068104910408F460C080930B019E
:1002900090930C01A0930D01B0930E018091090180
:1002A00090910A01892B29F4B0920A01A0920901C8
:1002B00004C010920A011092090130910901F7015E
:1002C0008491FE012491F8019491992309F43EC090
:1002D000882339F1833091F038F48130A9F08230ED
:1002E00001F584B58F7D12C0873091F08830A1F080
:1002F0008430B9F4809180008F7D03C080918000AC
:100300008F77809380000DC084B58F7784BD09C03E
:100310008091B0008F7703C08091B0008F7D809373
:10032000B000E92FF0E0EE0FFF1FCF018E589F4F76
:10033000FC01A591B4918FB7F8949C91311103C041
:100340002095292301C0292B2C938FBFC114D104E0
:0E03500009F47BCF0E94000078CFF894FFCF15
:00000001FF
`;

const blink = `
:10000000 0C94 5C00 0C94 6E00 0C94 6E00 0C94 6E00 CA
:10001000 0C94 6E00 0C94 6E00 0C94 6E00 0C94 6E00 A8
:10002000 0C94 6E00 0C94 6E00 0C94 6E00 0C94 6E00 98
:10003000 0C94 6E00 0C94 6E00 0C94 6E00 0C94 6E00 88
:10004000 0C94 1501 0C94 6E00 0C94 6E00 0C94 6E00 D0
:10005000 0C94 6E00 0C94 6E00 0C94 6E00 0C94 6E00 68
:10006000 0C94 6E00 0C94 6E00 0000 0000 2400 2700 29
:10007000 2A00 0000 0000 2500 2800 2B00 0404 0404 CE
:10008000 0404 0404 0202 0202 0202 0303 0303 0303 42
:10009000 0102 0408 1020 4080 0102 0408 1020 0102 1F
:1000A000 0408 1020 0000 0008 0002 0100 0003 0407 FB
:1000B000 0000 0000 0000 0000 1124 1FBE CFEF D8E0 B8
:1000C000 DEBF CDBF 21E0 A0E0 B1E0 01C0 1D92 A930 AC
:1000D000 B207 E1F7 0E94 5F01 0C94 CE01 0C94 0000 7E
:1000E000 E1EB F0E0 2491 EDE9 F0E0 9491 E9E8 F0E0 53
:1000F000 E491 EE23 09F4 3BC0 2223 39F1 2330 91F0 3F
:10010000 38F4 2130 A9F0 2230 01F5 24B5 2F7D 12C0 3A
:10011000 2730 91F0 2830 A1F0 2430 B9F4 2091 8000 EC
:10012000 2F7D 03C0 2091 8000 2F77 2093 8000 0DC0 89
:10013000 24B5 2F77 24BD 09C0 2091 B000 2F77 03C0 CC
:10014000 2091 B000 2F7D 2093 B000 F0E0 EE0F FF1F 54
:10015000 EE58 FF4F A591 B491 2FB7 F894 EC91 8111 0F
:10016000 03C0 9095 9E23 01C0 9E2B 9C93 2FBF 0895 A2
:10017000 3FB7 F894 8091 0501 9091 0601 A091 0701 85
:10018000 B091 0801 26B5 A89B 05C0 2F3F 19F0 0196 34
:10019000 A11D B11D 3FBF BA2F A92F 982F 8827 820F 0D
:1001A000 911D A11D B11D BC01 CD01 42E0 660F 771F 5D
:1001B000 881F 991F 4A95 D1F7 0895 8F92 9F92 AF92 09
:1001C000 BF92 CF92 DF92 EF92 FF92 0E94 B800 4B01 54
:1001D000 5C01 88EE C82E 83E0 D82E E12C F12C 0E94 21
:1001E000 B800 DC01 CB01 8819 9909 AA09 BB09 883E 2E
:1001F000 9340 A105 B105 58F0 21E0 C21A D108 E108 E9
:10020000 F108 88EE 880E 83E0 981E A11C B11C C114 71
:10021000 D104 E104 F104 19F7 FF90 EF90 DF90 CF90 43
:10022000 BF90 AF90 9F90 8F90 0895 1F92 0F92 0FB6 3E
:10023000 0F92 1124 2F93 3F93 8F93 9F93 AF93 BF93 6C
:10024000 8091 0101 9091 0201 A091 0301 B091 0401 FC
:10025000 3091 0001 23E0 230F 2D37 20F4 0196 A11D DA
:10026000 B11D 05C0 26E8 230F 0296 A11D B11D 2093 E4
:10027000 0001 8093 0101 9093 0201 A093 0301 B093 C8
:10028000 0401 8091 0501 9091 0601 A091 0701 B091 B0
:10029000 0801 0196 A11D B11D 8093 0501 9093 0601 EF
:1002A000 A093 0701 B093 0801 BF91 AF91 9F91 8F91 E7
:1002B000 3F91 2F91 0F90 0FBE 0F90 1F90 1895 7894 3B
:1002C000 84B5 8260 84BD 84B5 8160 84BD 85B5 8260 5B
:1002D000 85BD 85B5 8160 85BD 8091 6E00 8160 8093 0C
:1002E000 6E00 1092 8100 8091 8100 8260 8093 8100 75
:1002F000 8091 8100 8160 8093 8100 8091 8000 8160 85
:10030000 8093 8000 8091 B100 8460 8093 B100 8091 DF
:10031000 B000 8160 8093 B000 8091 7A00 8460 8093 07
:10032000 7A00 8091 7A00 8260 8093 7A00 8091 7A00 CE
:10033000 8160 8093 7A00 8091 7A00 8068 8093 7A00 4F
:10034000 1092 C100 EDE9 F0E0 2491 E9E8 F0E0 8491 39
:10035000 8823 99F0 90E0 880F 991F FC01 E859 FF4F 1E
:10036000 A591 B491 FC01 EE58 FF4F 8591 9491 8FB7 00
:10037000 F894 EC91 E22B EC93 8FBF C0E0 D0E0 81E0 E9
:10038000 0E94 7000 0E94 DD00 80E0 0E94 7000 0E94 C8
:10039000 DD00 2097 A1F3 0E94 0000 F1CF F894 FFCF 79
:00000001 FF
         
`;